Skip to content

Make schema-first translation the TypeScript 0.3 default - #540

Open
robgruen wants to merge 2 commits into
mainfrom
feat/schema-first-typescript-03
Open

robgruen wants to merge 2 commits into
mainfrom
feat/schema-first-typescript-03

Conversation

@robgruen

Copy link
Copy Markdown
Contributor

Implement the TypeScript candidate for the one-time 0.3.x behavior proposed in #539, alongside Guido’s Python #241. Please hold merge until the project-direction proposal is approved and merged.

On a fresh request the translator submits application-owned instructions and schema as system, followed by the verbatim request once as user. Caller context keeps its roles. { promptLayout: "legacy" } preserves the previous request builder and layout; an unmigrated request override is reported before dispatch rather than promoted to system text or silently skipped.

The Program translator describes both the JSON program to return and the API it can call. The affected examples, migration docs, package version, and example dependency ranges are updated. This does not change the other languages’ APIs or publish a package.

Verified locally on Node 24.22.1: npm ci, npm run build-all, npm test (433 passing, including 13 package-consumer checks), all 12 examples resolved the candidate workspace, and the docs site built. A separately installed npm pack tarball passed the same offline message check as Python: fresh request, follow-up with history, forced validation repair, and validated final result.

Keep the 0.2 request builder behind an explicit legacy layout. Migrate the Program translator and examples, and verify role boundaries, repair, workspace resolution, and packaged consumers with deterministic models.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the schema-first prompting changes and their legacy migration path.

No open issues 🎉

1 file not reviewed
  • typescript/package-lock.json: Generated file
What changed in this PR

Implements the TypeScript candidate for #539’s proposed 0.3 schema-first prompting, with an explicit legacy migration path. The changes cover the library, examples, and documentation; they do not publish a package.

Changes:

  • Separate system instructions and schema from the verbatim user request, preserving caller context roles.
  • Migrate Program and example prompts, and align package versions and example dependencies.
  • Add prompt-layout, repair, example, and package-consumer checks alongside migration guidance.
File Description
typescript/​tests/​package.test.mjs Checks published prompt APIs and default message layout.
typescript/​tests/​examples.test.mjs Checks workspace resolution and migrated example prompts.
typescript/​test/​prompt-layout.test.ts Covers default, legacy, history, and migration-error behavior.
typescript/​test/​program.test.ts Checks Program schemas, layouts, and repair messages.
typescript/​test/​failure.test.ts Verifies repair roles and original response preservation.
typescript/​src/​typechat.ts Adds schema-first defaults, system builder, and legacy option.
typescript/​src/​ts/​program.ts Adapts Program prompts to both layouts.
typescript/​src/​model.ts Updates comments describing prompt roles and adapter expectations.
typescript/​README.md Documents 0.3 prompts and migration.
typescript/​package.json Sets the candidate version to 0.3.0.
typescript/​package-lock.json Aligns root and example dependency versions.
typescript/​examples/​sentiment/​package.json Targets TypeChat 0.3.
typescript/​examples/​sentiment-zod/​package.json Targets TypeChat 0.3.
typescript/​examples/​restaurant/​package.json Targets TypeChat 0.3.
typescript/​examples/​music/​package.json Targets TypeChat 0.3.
typescript/​examples/​multiSchema/​src/​router.ts Moves classification instructions into the system prompt.
typescript/​examples/​multiSchema/​package.json Targets TypeChat 0.3.
typescript/​examples/​math/​package.json Targets TypeChat 0.3.
typescript/​examples/​healthData/​src/​translator.ts Separates application instructions from assistant history.
typescript/​examples/​healthData/​package.json Targets TypeChat 0.3.
typescript/​examples/​drawing/​src/​main.ts Passes prior requests as user-context sections.
typescript/​examples/​drawing/​package.json Targets TypeChat 0.3.
typescript/​examples/​crossword/​src/​translator.ts Separates system instructions, screenshot context, and request.
typescript/​examples/​crossword/​package.json Targets TypeChat 0.3.
typescript/​examples/​coffeeShop/​package.json Targets TypeChat 0.3.
typescript/​examples/​coffeeShop-zod/​package.json Targets TypeChat 0.3.
typescript/​examples/​calendar/​package.json Targets TypeChat 0.3.
site/​src/​docs/​typescript/​basic-usage.md Explains layouts, context, migration, and repair behavior.

Review effort: Balanced

TypeScript now makes the same one repair attempt as Python and TypeChat.NET when a reply has no JSON object or cannot be parsed. Validation failures still repair once, and attemptRepair = false still returns immediately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing or malformed JSON now triggers a second model call by default, adding latency and usage instead of preserving TypeScript’s immediate-failure behavior.

1 open issue
1 file not reviewed
  • typescript/package-lock.json: Generated file

Review effort: Balanced

const validation = schemaValidation.success ? typeChat.validateInstance(schemaValidation.data) : schemaValidation;
if (validation.success) {
return finish(validation);
else if (!attemptRepair) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants